#include "CNetworkIO.h"

CNetworkIO::CNetworkIO()
{
  //ctor
}

CNetworkIO::~CNetworkIO()
{
  //dtor
}


wchar_t* CNetworkIO::readWcs(BitStream &bs)
{
  u16 len;
  wchar_t *text;
  // Read the text length
  bs.Read(len);

  // Get the actual text length
  text = new wchar_t[len/2];

  // Read the actual text
  bs.Read((char*)text, len);

  return text;
}


void CNetworkIO::writeWcs(BitStream &bs, const wchar_t* wcs)
{
  // Convert the text into binary data for bitstream transfer
  wchar_t *text = const_cast<wchar_t*> (wcs);
  char *data = reinterpret_cast<char*> (text); //(char*) text;

  // note that length need to be +1 for the null terminator
  unsigned short len = ( wcslen(wcs) + 1 ) * 2;

  // Write the length of the data
  bs.Write( len );

  // Write the data itself
  bs.Write(data, len);
}
